package com.langsin.util;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
    //查询结果的总记录数
    private int totalNum;
    //每页显示的记录数
    private int pageSize;
    //总页数
    private int totalPage;
    //当前页数
    private int currentPage = 1;
    //显示的结果集
    private List<T> list = new ArrayList<T>();

    public Page(int pageSize){
        this.pageSize = pageSize;
    }

    public int getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(int totalNum) {
        this.totalNum = totalNum;
        if(this.totalNum % this.pageSize == 0){
            this.totalPage = this.totalNum / this.pageSize;
        }else{
            this.totalPage = this.totalNum / this.pageSize + 1;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        if(currentPage < 0){
            this.currentPage = 1;
        }else if (currentPage > this.totalPage){
            this.currentPage = this.totalPage;
        }else{
            this.currentPage = currentPage;
        }
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
